home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / games / 3d_hyper / 3d_hyper.dcr / Scripts_72_Make Track Rigid Bodies.ls < prev    next >
Encoding:
Text File  |  2011-06-09  |  3.6 KB  |  129 lines

  1. property pmodel, pcamera, pMember, pSprite, pFriction, pRestitution, pType, pCreated, pHavok
  2. global gWorld
  3.  
  4. on beginSprite me
  5.   pSprite = sprite(me.spriteNum)
  6.   pHavok = pSprite.pHavok
  7.   pMember = pSprite.member
  8.   pcamera = pSprite.camera
  9.   pCreated = 0
  10.   if voidp(pmodel) then
  11.     pmodel = "All"
  12.   end if
  13. end
  14.  
  15. on endSprite me
  16. end
  17.  
  18. on makeRigidBody me, mdlName
  19.   bConcave = offset("Concave", pType)
  20.   bSphere = offset("Sphere", pType)
  21.   bBox = offset("Box", pType)
  22.   if not getPos(pMember.model(mdlName).modifier, #meshDeform) then
  23.     pMember.model(mdlName).addModifier(#meshDeform)
  24.   end if
  25.   if bConcave then
  26.     rb = pHavok.makeFixedRigidBody(mdlName, 0)
  27.   else
  28.     if bSphere then
  29.       rb = pHavok.makeFixedRigidBody(mdlName, 1, #sphere)
  30.     else
  31.       if bBox then
  32.         rb = pHavok.makeFixedRigidBody(mdlName, 1, #box)
  33.       else
  34.         rb = pHavok.makeFixedRigidBody(mdlName)
  35.       end if
  36.     end if
  37.   end if
  38.   rb.friction = pFriction
  39.   rb.restitution = pRestitution
  40.   return rb
  41. end
  42.  
  43. on enterFrame me
  44.   if not pCreated then
  45.     pCreated = 1
  46.     if "All" = pmodel then
  47.       repeat with j = 1 to pMember.model.count
  48.         if string(pMember.model[j]) contains "model" then
  49.           me.makeRigidBody(pMember.model[j].name)
  50.         end if
  51.       end repeat
  52.     else
  53.       repeat with i = 1 to gWorld.group("HavokTrackGroup").child.count
  54.         me.makeRigidBody("HavokTrack_" & i)
  55.       end repeat
  56.     end if
  57.   end if
  58. end
  59.  
  60. on exitFrame me
  61. end
  62.  
  63. on isOKToAttach aScript, aSpriteType, aSpriteNum
  64.   case aSpriteType of
  65.     #graphic:
  66.       case sprite(aSpriteNum).member.type of
  67.         #shockwave3d:
  68.           if aScript.getmodels(sprite(aSpriteNum).member, []).count > 0 then
  69.             return 1
  70.           else
  71.             return 0
  72.           end if
  73.         #text:
  74.           if sprite(aSpriteNum).member.displayMode = #mode3d then
  75.             return 1
  76.           else
  77.             return 0
  78.           end if
  79.       end case
  80.     #script:
  81.       return 0
  82.   end case
  83.   return 0
  84. end
  85.  
  86. on getPropertyDescriptionList aScript
  87.   if the floatPrecision < 4 then
  88.     set the floatPrecision to 4
  89.   end if
  90.   if the currentSpriteNum > 0 then
  91.     tGPDList = [:]
  92.     tList = []
  93.     tList = aScript.getmodels(sprite(the currentSpriteNum).member, tList)
  94.     tList.addAt(1, "All")
  95.     if tList.count > 1 then
  96.       tGPDList[#pmodel] = [#comment: "Which model", #format: #string, #range: tList, #default: tList[1]]
  97.     else
  98.       nothing()
  99.       pmodel = tList[1]
  100.     end if
  101.     tGPDList[#pRestitution] = [#comment: "Restitution", #format: #float, #default: 0.29999999999999999]
  102.     tGPDList[#pFriction] = [#comment: "Friction", #format: #float, #default: 0.29999999999999999]
  103.     tTypeList = ["Convex:Sphere", "Convex:Box", "Convex:Hull", "Concave"]
  104.     tGPDList[#pType] = [#comment: "Type", #format: #string, #range: tTypeList, #default: tTypeList[3]]
  105.     return tGPDList
  106.   end if
  107. end
  108.  
  109. on getBehaviorTooltip aScript
  110.   tString1 = "Creates fixed rigid bodies from 3D models" & RETURN & RETURN
  111.   tString2 = "-" && "Type" && ":" && "Local Action" & RETURN
  112.   tString3 = "-" && "Usage" && ":" && "Drop this onto a scene with physics"
  113.   return tString1 & tString2 & tString3
  114. end
  115.  
  116. on getBehaviorDescription aScript
  117.   tString1 = "CREATES A FIXED RIGID BODY" & RETURN & RETURN & "PARAMETERS:" & RETURN & "- Model to create rigid body from" & RETURN & "- Restitution" & RETURN & "- Friction" & RETURN & "- Type" & RETURN & "PERMITTED SPRITE TYPES:" & RETURN & "- Shockwave 3D"
  118.   return tString1
  119. end
  120.  
  121. on getmodels me, amember, aList
  122.   repeat with j = 1 to amember.model.count
  123.     if string(amember.model[j]) contains "model" then
  124.       aList.add(amember.model[j].name)
  125.     end if
  126.   end repeat
  127.   return aList
  128. end
  129.